package com.atguigu.spzx.manager.controler;


import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name="用户权限")
@RestController
@RequestMapping(value = "/admin/system/sysRole")
public class SyRoleController {

    @Autowired
    private SysRoleService sysRoleService;
   //角色列表
    @PostMapping("/findByPage/{current}/{limit}")
    public Result findByPage(@PathVariable("current") Integer current,
                             @PathVariable("limit")  Integer limit,
                             @RequestBody SysRoleDto sysRoleDto){
        PageInfo<SysRole> pageInfo=sysRoleService.findByPage(sysRoleDto,current,limit);

        return  Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    //角色增加
    @PostMapping("/role/add")
    public  Result roleAdd(@RequestBody SysRole sysRole){
        System.out.println(sysRole+"我是提交的资料");
        Boolean isShow=    sysRoleService.roleAdd(sysRole);
        System.out.println(isShow+"我是成功失败");
        return  Result.build(isShow,ResultCodeEnum.SUCCESS);
    }
    //角色删除
    @GetMapping("/role/del/{id}")
    public  Result roleDel(@PathVariable Long id){
     Boolean isShow=sysRoleService.roleDel(id);
     return  Result.build(isShow,ResultCodeEnum.SUCCESS);
    }
    //角色修改
    @PostMapping("/role/update")
    public  Result roleUpdate(@RequestBody SysRole sysRole){
        Boolean isShow=sysRoleService.update(sysRole);
        return  Result.build(isShow,ResultCodeEnum.SUCCESS);
    }
}
